package com.gzz.orchid.common.core.model;

import lombok.Getter;
import lombok.Setter;

/**
 * 分页实体类
 *
 * @author higmd
 */
public class Pagination {
    // 页面记录大小
    @Setter
    @Getter
    private int size = 10;
    // 当前页
    @Setter
    @Getter
    private int current = 1;
    // 总记录
    @Getter
    private int total = 0;
    // 总页数
    @Getter
    private int pages = 0;
    // 上次记录位置
    @Setter
    private int offset = 0;

    /**
     * 构造函数
     */
    public Pagination() {

    }

    /**
     * 构造函数 *
     *
     * @param size 页大小
     */
    public Pagination(int size) {
        this.size = size;
    }

    public void setTotal(int total) {
        this.total = total;
        this.pages = (this.total % this.size == 0) ? (this.total / this.size)
                : (this.total / this.size + 1);
    }

    public int getOffset() {
        this.offset = this.size * (this.current - 1);
        return Math.max(this.offset, 0);
    }
}
